package io.github.uicdb.et.block;

import io.github.uicdb.et.ElementalTheory;
import io.github.uicdb.et.net.CCraftInPosPayload;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull;

public class ExtractScreen extends AbstractContainerScreen<ExtractMenu> {
    private static final ResourceLocation CONTAINER_BACKGROUND = ResourceLocation.fromNamespaceAndPath(ElementalTheory.MODID,"textures/gui/extractor_background.png");

    public ExtractScreen(ExtractMenu menu, Inventory playerInventory, Component title) {
        super(menu, playerInventory, title);

        this.imageHeight = 196 ;
        this.imageWidth = 176;
        this.inventoryLabelY = this.imageHeight - 94;

    }

    @Override
    protected void init() {
        super.init();
        this.topPos = (this.height - this.imageHeight) / 2;
        this.leftPos = (this.width - this.imageWidth) / 2;
        addRenderableWidget(new Button.Builder(Component.translatable("gui.extract_screen.craft"), new Button.OnPress() {
            @Override
            public void onPress(@NotNull Button button) {
                ICraft.requireCraft(menu.getPos());
            }
        }).bounds(leftPos+136,topPos+99,32,12).build());
    }

    public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
        super.render(guiGraphics, mouseX, mouseY, partialTick);

        renderInfo(guiGraphics,0,101,15);
        renderInfo(guiGraphics,1,145,52);
        renderInfo(guiGraphics,2,127,85);
        renderInfo(guiGraphics,3,32,85);
        renderInfo(guiGraphics,4,22,30);
        renderInfo(guiGraphics,5,96,78);
        renderInfo(guiGraphics,6,64,42);
        this.renderTooltip(guiGraphics, mouseX, mouseY);
    }

    private void renderInfo(@NotNull GuiGraphics guiGraphics, int index,int x,int y) {
          guiGraphics.drawString(minecraft.font,menu.getContainerData().get(index)+"", leftPos+ x,topPos + y, ChatFormatting.GOLD.getColor());
    }

    protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
        guiGraphics.blit(CONTAINER_BACKGROUND, leftPos, topPos , this.imageWidth, this.imageHeight,0, 0,this.imageWidth,this.imageHeight,this.imageWidth,this.imageHeight);
    }
}
